from loguru import logger
from datetime import datetime
from sqlalchemy.orm import Session
from sqlalchemy import select

from app.database.oracle import  oracle_session
from app.schemas.qm import CreateQm
from app.crud import qm_crud 

from app.models import Station,Dev,Img
from app.schemas.img import CVImg
from cv.classify.classify_state import ClassifyState
from cv.classify.classify_th import ClassifyTH


def create_qm_data(timestamp:int,station:Station,dev:Dev,short_cfy:ClassifyState,long_cfy:ClassifyTH=None):
    if long_cfy is None:
        qm_obj = CreateQm(dev_no=dev.dev_no,
                            station_no = int(station.name.split("LM")[1]),
                            created_at=datetime.fromtimestamp(timestamp),
                            name=str(timestamp),
                            state=short_cfy.state_text) 
    else:
        qm_obj = CreateQm(dev_no=dev.dev_no,
                            station_no = int(station.name.split("LM")[1]),
                            created_at=datetime.fromtimestamp(timestamp),
                            name=str(timestamp),
                            state=short_cfy.state_text,
                            temp=long_cfy.temp_num,
                            temp_set=long_cfy.temp_set_num,
                            humi=long_cfy.humi_num,
                            humi_set=long_cfy.humi_set_num) 

    qm_crud.create(qm_obj)

    

    





